﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace IrisGenerator.Framework.Reflection
{
    public class MethodCallParameter
    {
        public string ParameterName { get; set; }
        public string PropertyName { get; set; }
        public object Value { get; set; }

        public MethodCallParameter(string propertyName)
        {
            this.PropertyName = propertyName;
   
        }

        public MethodCallParameter(string parameterName, object parameterValue)
        {
            this.ParameterName = parameterName;
            this.Value = parameterValue;
        }

        public void Clear()
        {
            this.ParameterName = string.Empty;
            this.PropertyName = string.Empty;
            this.Value = null; 
        }

        public void BindValue(object sourceObject)
        {
            if (string.IsNullOrEmpty(this.PropertyName) || sourceObject == null)
                return ;

            PropertyInfo property = GetProperty(sourceObject, this.ParameterName);

            this.Value=property.GetValue(sourceObject, null);
        }

        public static PropertyInfo GetProperty(object sourceObject, string propertyName)
        {
            return sourceObject.GetType().GetProperty(propertyName);
        }


    }
}
